package thread.pool.executor_service;

import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;

public class ExecutorServiceSubmit {

	public static void main(String[] args) {
		ExecutorService service = Executors.newSingleThreadExecutor();

		Future future = service.submit(new Runnable() {
			public void run() {
				System.out.println("Asynchronous task");
			}
		});

		try {
			future.get(); // returns null if the task has finished correctly.
		} catch (ExecutionException ex) {
			System.out.println(ex.toString());
		} catch (InterruptedException ex) {
			System.out.println(ex.toString());
		}
	}

}
